import 'package:flutter/material.dart';
import 'package:learn_flutter/lesson10/i18n/localizations.dart';

class HYLocalizationsDelegate extends LocalizationsDelegate<HYLocalizations> {
  static HYLocalizationsDelegate delegate = HYLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) {
    return ['zh', 'en'].contains(locale.languageCode);
  }

  @override
  Future<HYLocalizations> load(Locale locale) async{
    final localizations = HYLocalizations(locale);
    await localizations.loadJson();
    return localizations;
    // return SynchronousFuture((HYLocalizations(locale)));
  }

  @override
  bool shouldReload(LocalizationsDelegate<HYLocalizations> old) => false;
}
